﻿using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.BIZ;
using AnyOffice.Components;
using AnyOffice.DAL;
using log4net;
using Microsoft.ApplicationBlocks.Data;
namespace AnyOffice.general.system.user
{
    public partial class delete : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["dept_id"] == null) ? 0 : int.Parse(Request.QueryString["dept_id"].ToString());
                string str = (Request.QueryString["user_id"] == null) ? "" : Request.QueryString["user_id"].ToString();
                UsersDao dao = new UsersDao();
                try
                {
                    dao.Delete(base.Conn, str);
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                }
                try
                {
                    DirectoryInfo info = new DirectoryInfo(Server.MapPath(@"/attachment/file_folder\" + str));
                    if (info.Exists)
                    {
                        info.Delete(true);
                    }
                    string path = string.Empty;
                    path = Server.MapPath(@"/attachment/helper/global\" + str + ".bin");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    path = Server.MapPath(@"/attachment/helper/knowledge\" + str + ".bin");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    path = Server.MapPath(@"/attachment/helper/netdisk\" + str + ".bin");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
                catch (Exception exception2)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception2);
                    }
                }
                ConfigManager manager = new ConfigManager();
                string sqlForUserDelete = manager.SqlForUserDelete;
                if (sqlForUserDelete != string.Empty)
                {
                    sqlForUserDelete = VBString.Replace(sqlForUserDelete, "@userid", str);
                    try
                    {
                        SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, sqlForUserDelete);
                    }
                    catch (Exception exception3)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("", exception3);
                        }
                    }
                }
                WorkFlowBiz biz = new WorkFlowBiz();
                DataTable table = biz.ByUserId(base.Conn, str);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        biz.Delete(base.Conn, Convert.ToInt32(table.Rows[i]["RunId"].ToString()), base.User.Identity.Name, true);
                    }
                }
                string str4 = "UserId=" + str.ToString();
                SysLog.Log(base.Conn, 8, str4);
                this.lblMessage.Text = base.ShowPrompt("删除用户成功", "user_dept.aspx?dept_id=" + num.ToString());
            }

        }
    }
}